<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{$Think.config.site.title} - 客户余额退款</title>
    <meta name="keywords" content="{$Think.config.site.keywords}">
    <meta name="description" content="{$Think.config.site.description}">
    <link href="{$Think.config.site.resource_url}css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/plugins/iCheck/custom.css" rel="stylesheet">
     <!-- Data Tables -->
    <link href="{$Think.config.site.resource_url}css/animate.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/style.css?v=4.1.0" rel="stylesheet">
</head>
<style>
    .fa{ color:#1ab394;  cursor:pointer;}
    .form-control, .single-line { width:30%; display: inline-block; }
</style>
<body >
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
            <form method="post" id="myforms"  action="">
                <table class="table table-hover" id="listtable">
                <input type="hidden" name="id" value="{$v.id}">
                    <tr>
                        <!-- <th><input  id="checkall"  type="checkbox" class="i-checks" value="1"> 全选</th> -->
                        <th>{:lang('用户名')}</th>
                        <th>{:lang('订单号')}</th>
                        <th>{:lang('充值余额')}</th>
                        <th>{:lang('交易日期')}</th>
                    </tr>
                    {volist name="list" id="vo"}
                    <tr>
                        <!-- <td><input type="checkbox" name="ids[]" value="{$vo.id}" class="i-checks"></td> -->
                        <td>{$vo.name}</td>
                        <td>{$vo.order_no}</td>
                        <td>{$vo.balance}</td>
                        <td>{$vo.payment_date|date="Y-m-d H:i:s",###}</td>
                    </tr>
                    {/volist}
                    <tr><td colspan="5">&nbsp;</td></tr>
                    <tr style="padding-top: 15px;">
                        <td colspan="5" style="border: 0px;" >
                            <p>{:lang('温馨提示:退款金额不能超过订单实际支付的金额！退款时,直接输入要退款的金额')}</p>
                            <p>{:lang('当前余额退款最多可退')}: <font  style="color:red;">{$sum ?? '0'}</font> {:lang('元')};　　{:lang('当前余额')}: <font  style="color:red;">{$v.balance ?? '0'} </font>{:lang('元')}</p>

                        </td>
                    </tr>
                    <tr><td colspan="5">&nbsp;</td></tr>
                    <tr style="padding-top: 15px;">
                        <td colspan="5" class="text-right">{:lang('输入退款金额')}:<input type="text" class="input-sm form-control" placeholder="{:lang('输入退款金额')}" name="refunds" id="refunds"><button class="btn btn-primary" id="onbtn">{:lang('提交')}</button></td>
                    </tr>
                </table>
                </form>
            </div>
        </div>
    </div>

     <script src="{$Think.config.site.resource_url}js/jquery.min.js?v=2.1.4"></script>
    <script src="{$Think.config.site.resource_url}js/bootstrap.min.js?v=3.3.6"></script>
    <!-- Peity -->
    <script src="{$Think.config.site.resource_url}js/plugins/peity/jquery.peity.min.js"></script>
    <!-- 自定义js -->
    <script src="{$Think.config.site.resource_url}js/content.js?v=1.0.0"></script>
    <!-- iCheck -->
    <script src="{$Think.config.site.resource_url}js/plugins/iCheck/icheck.min.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/layer/layer.js"></script>
    <script type="text/javascript">
    $(function(){
        /*$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});
        //全选
        $("#checkall").bind("ifChecked",function(){
            $("input[name='ids[]']").iCheck("check");
        });
        //取消全选
        $("#checkall").bind("ifUnchecked",function(){
            $("input[name='ids[]']").iCheck("uncheck");
        });*/
        var res = /^(([1-9]\d*)|\d)(\.\d{1,2})?$/;
        $('#onbtn').click(function(){
            var refunds = $('#refunds').val();
            var ids = $("input[name='ids[]']")
            if(refunds==''){
                $('#refunds').focus();
                layer.msg("{:lang('输入退款金额')}", {icon: 5});
                return false;
            }
            if(!res.test(refunds)){
                $('#refunds').focus();
                layer.msg("{:lang('请正确输入整数或者小数点两位!')}", {icon: 5});
                return false;
            }
            var max = {$sum ?? "0"};
            if(refunds > max){
                $('#refunds').focus();
                layer.msg("{:lang('退款金额不能超过客户实际订单支付的总金额!')}", {icon: 5});
                return false;
            }
            if(refunds<=0){
                $('#refunds').focus();
                layer.msg("{:lang('退款金额不能小于等于零!')}", {icon: 5});
                return false;
            }
           /* var len = $("input[name='ids[]']:checked").length;
            if(len==0){
                layer.msg('请选择要退款的订单!', {icon: 5});
                return false;
            }*/
            //alert("你一共选中了"+len+"个复选框");
            var formdata = $('#myforms').serialize();
            $.ajax({
                type : 'POST',
                url  : '<?php echo \think\Request::instance()->root(); ?>/<?php echo \think\Request::instance()->module(); ?>/Orders/rebalance',
                dataType : 'json',
                data : formdata,
                async : false,
                success : function(result){
                    if(0 == result.code){
                        layer.msg(result.msg, {icon: 1});
                        parent.location.reload();
                    }else{
                        layer.msg(result.msg, {icon: 5});
                    }
                },
                error : function(){
                    layer.msg("{:lang('服务器错误！请稍后重试')}", {icon: 2});
                }
            })
        })


    });
    </script>
</body>
</html>